import React from 'react';
import dva,{connect} from './dva'
const app = dva()
app.model({
  namespace:'counter',//因为一个dvaapp中可以定义很多个模型
  state:{number:0}, //每个model里可以定义一个状态
  reducers:{
    add(state){
      return { number:state.number+1 }
    },
    minus(state){
      return { number:state.number-1 }
    }
  },

})

function Counter(props){
  return (
    <div>
        <p>{props.number}</p>
        <button onClick={() => props.dispatch({ type: "counter/add" })}>+</button>
        <button onClick={() => props.dispatch({ type: "counter/minus" })}>-</button>
    </div>
  )
}

//store.getState() ={counter:{number:0}}
const ConnectedCounter = connect(state=>state.counter)(Counter)
// 指定要渲染的内容
app.router(()=><ConnectedCounter />)
// 开始渲染，原理就是 ReactDOM.render(()=><ConnectedCounter />,'#root')
app.start('#root')

